package com.tour.controller.portal;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tour.common.Const;
import com.tour.common.ResponseCode;
import com.tour.common.ServerResponse;
import com.tour.pojo.EasyUIDataGridResult;
import com.tour.pojo.TrDesc;
import com.tour.pojo.TrevalProject;
import com.tour.pojo.User;
import com.tour.service.ITrevalProjectService;
import com.tour.service.IUserService;

/**
 * Created by fivedeath
 */
@Controller
@RequestMapping("/trevalproject/")
public class TrevalProjectController {
	
//	@Value("${IMAGE_SERVER_URL}")
//	private String IMAGE_SERVER_URL;

    @Autowired
    private IUserService iUserService;
    @Autowired
    private ITrevalProjectService iTrevalProjectService;
    
    /**
     * 获取项目描述
     * @param session
     * @param trevalProject
     * @param desc
     * @return
     */
    @RequestMapping(value="getDesc/{descId}",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse<TrDesc> projectSave(HttpSession session, @PathVariable Long descId){
    	//填充我们增加项目的业务逻辑
    	return iTrevalProjectService.getTrDescById(descId);
    }

    @RequestMapping("detail.do")
    @ResponseBody
    public TrevalProject getDetail(HttpSession session,Long id){
            //填充业务
            return iTrevalProjectService.manageProjectDetail(id).getData();
    }
    @RequestMapping("detail/{id}")
    @ResponseBody
    public ServerResponse<TrevalProject> getTrDetail(HttpSession session,@PathVariable Long id){
    	//填充业务
    	return iTrevalProjectService.manageProjectDetail(id);
    }

    @RequestMapping("list.do")
    @ResponseBody
    public EasyUIDataGridResult getList(HttpSession session, @RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value = "rows",defaultValue = "10") int rows){
    	//填充业务
            return iTrevalProjectService.getProjectList(page,rows);
    }
    
    @RequestMapping("trlist.do")
    @ResponseBody
    public ServerResponse getTrList(HttpSession session, @RequestParam(value = "nowPage",defaultValue = "1") int page,@RequestParam(value = "size",defaultValue = "10") int rows){
    	//填充业务
    	return iTrevalProjectService.getTrList(page,rows);
    }

    @RequestMapping("search.do")
    @ResponseBody
    public ServerResponse projectSearch(HttpSession session,String projectName,Long projectId, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,@RequestParam(value = "pageSize",defaultValue = "10") int pageSize){
        User user = (User)session.getAttribute(Const.CURRENT_USER);
        if(user == null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录管理员");

        }
        if(iUserService.checkAdminRole(user).isSuccess()){
            //填充业务
            return iTrevalProjectService.searchProject(projectName,projectId,pageNum,pageSize);
        }else{
            return ServerResponse.createByErrorMessage("无权限操作");
        }
    }
    
    //查询总数
    @RequestMapping("getTrCount.do")
    @ResponseBody
    public ServerResponse getCount(){
            //填充业务
            return iTrevalProjectService.getTrCount();
    }
}
